package tk.xboot.boot;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;

/**
 * 在SpringBootApplication上使用@ServletComponentScan注解后，Servlet、Filter、Listener可以直接
 * 通过@WebServlet、@WebFilter、@WebListener注解自动注册，无需其他代码。
 *
 */
@ServletComponentScan
@PropertySources(value = {@PropertySource("classpath:config/website.properties")})
@SpringBootApplication
public class BootMain {
    private static final Logger LOGGER = LoggerFactory.getLogger(BootMain.class);
    private static final String PID_FILE_NAME = "pid";
    private static ConfigurableApplicationContext ac;

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(BootMain.class);
        //app.addListeners(new ApplicationPidFileWriter(PID_FILE_NAME));
        //app.addListeners(new ApplicationPidFileWriter());
        app.setRegisterShutdownHook(true);
        ac = app.run(args);

        for (String str : ac.getEnvironment().getActiveProfiles()) {
            LOGGER.info(str);
        }
        LOGGER.info("Boot Server started.");

        SimpleUrlHandlerMapping mapping;
        ResourceHttpRequestHandler handler;
        RequestMappingHandlerMapping handlerMapping;

        ConditionEvaluationReportLoggingListener loggingListener;

        //The same with : spring.main.web-application-type=none
		/*new SpringApplicationBuilder()
                .sources(BootApplication.class)
                .web(WebApplicationType.NONE)
                .run(args);*/
    }
}